import { defineStore } from 'pinia'
const history = ref([])
import { ref, computed } from 'vue'

export const useCounterStore = defineStore('counter', () => {
  // 状态
  const count = ref(0)

  // getter
  const doubleCount = computed(() => count.value * 2)

  // actions
  function increment() {
    count.value++
    history.value.push(count.value)
  }

  function decrement() {
    count.value--
    history.value.push(count.value)
  }

  function reset() {
    count.value = 0
    history.value = []
  }

  return { 
    count, 
    history, 
    doubleCount, 
    increment, 
    decrement, 
    reset 
  }
})
